<template>
    <el-carousel :interval="3000" arrow="always" type="card" @change="handleCarouselChange">
        <!-- 第一个轮播项 -->
        <el-carousel-item>
            <img :src="image1" alt="Slide 1" class="carousel-image" :style="{ filter: blurAmount }">
        </el-carousel-item>
        <!-- 第二个轮播项 -->
        <el-carousel-item>
            <img :src="image2" alt="Slide 2" class="carousel-image" :style="{ filter: blurAmount }">
        </el-carousel-item>
        <!-- 第三个轮播项 -->
        <el-carousel-item>
            <img :src="image3" alt="Slide 3" class="carousel-image" :style="{ filter: blurAmount }">
        </el-carousel-item>
    </el-carousel>
</template>

<script setup>
import { ref } from 'vue';

// 导入图片
const image1 = new URL('@/assets/swiper1.png', import.meta.url).href;
const image2 = new URL('@/assets/swiper2.png', import.meta.url).href;
const image3 = new URL('@/assets/swiper3.jpg', import.meta.url).href;

// 动态模糊的值
const blurAmount = ref('1px');

// 处理轮播图切换事件
const handleCarouselChange = () => {
    // 切换时先增加模糊效果
    blurAmount.value = '5px';
    setTimeout(() => {
        // 一段时间后恢复清晰
        blurAmount.value = '0px';
    }, 300); // 300 毫秒后恢复清晰
};
</script>

<style scoped>
.carousel-image {
    width: 100%;
    height: 600px;
    object-fit: cover;
    transition: filter 0.3s ease; /* 添加过渡效果，使模糊变化更平滑 */
}
</style>